<template>
  <div>
    <el-table :data="tableData" style="width: 100%" stripe border>
      <el-table-column type="index" label="序号" />
      <el-table-column header-align="center" prop="title" label="标题" />
      <el-table-column header-align="center" align="center" label="封面图">
        <template slot-scope="scope">
          <img
            :src="'http://www.daruilife.cn' + scope.row.cover"
            style="max-width:100px;max-height:100px;"
          >
        </template>
      </el-table-column>
      <el-table-column prop="desc" label="描述" />
      <el-table-column
        header-align="center"
        align="center"
        prop="add_time"
        label="创建时间"
      />
      <el-table-column header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            @click="openEdit(scope.row.id)"
          >编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="query.page"
      :page-size="query.pageSize"
      layout="total, prev, pager, next, jumper"
      :total="400"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { getList } from '@/api/article.js'
export default {
  data() {
    return {
      total: 0,
      query: {
        domain: 'www.daruilife.cn',
        page: 1,
        pageSize: 10
      },
      tableData: []
    }
  },
  created() {
    getList(this.query).then(res => {
      this.tableData = res.data
    })
  },
  methods: {
    handleCurrentChange(page) {
      this.query.page = page
      getList(this.query).then(res => {
        this.tableData = res.data
      })
    },
    openEdit(id) {
      console.log(id)
    },
    del(id) {
      console.log(id)
    }
  }
}
</script>

<style lang="scss" scoped></style>
